import 'package:flutter/material.dart';
import 'package:fsuper/fsuper.dart';

class PeriodWidget extends StatefulWidget {
  int period;

  Function onChange;

  PeriodWidget(this.period, this.onChange);

  @override
  _PeriodWidgetState createState() => _PeriodWidgetState();
}

class _PeriodWidgetState extends State<PeriodWidget> {
  @override
  Widget build(BuildContext context) {
    return FSuper(
      height: 32,
      width: ('发送周期(${widget.period}ms)'.length) * 12.0,
      text: "发送周期(${widget.period}ms)",
      textSize: 12,
      textAlignment: Alignment.center,
      child1: Icon(Icons.arrow_downward, size: 18),
      child1Alignment: Alignment.centerLeft,
      onChild1Click: () {
        setState(() {
          widget.period -= 500;
          if (widget.period <= 500) {
            widget.period = 500;
          }
        });
        widget.onChange(widget.period);
      },
      child2: Icon(Icons.arrow_upward, size: 18),
      child2Alignment: Alignment.centerRight,
      onChild2Click: () {
        setState(() {
          widget.period += 500;
          if (widget.period > 5000) {
            widget.period = 5000;
          }
        });
        widget.onChange(widget.period);
      },
    );
  }
}
